package com.myrock.zlbandy.gorock.rock.ui;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;

import android.support.v4.view.ViewPager;

import android.view.ViewGroup;

import android.view.WindowManager;

import android.widget.TextView;


import com.android.volley.toolbox.ImageLoader;

import com.android.volley.toolbox.NetworkImageView;
import com.gigamole.navigationtabstrip.NavigationTabStrip;
import com.myrock.zlbandy.gorock.rock.tools.NetRequest;
import com.myrock.zlbandy.gorock.HttpModel.Model.RockInfo;
import com.myrock.zlbandy.gorock.rock.tools.LruImageCache;
import com.myrock.zlbandy.gorock.R;
import com.myrock.zlbandy.gorock.my.adapter.FragmentAdapter;

import java.util.ArrayList;
import java.util.List;

public class RockInfoActivity extends FragmentActivity{
    private FragmentAdapter mFragmentAdapter;
    private RockInfo rockInfo;
    private NetworkImageView imageView;
    private TextView rockname;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rock_info);

        Intent intent = getIntent();
        rockInfo =  (RockInfo)intent.getSerializableExtra("rockInfo");
        imageView = (NetworkImageView) findViewById(R.id.imageView);
        LruImageCache lruImageCache = LruImageCache.instance();
        ImageLoader imageLoader = new ImageLoader(NetRequest.getInstance(getApplicationContext()),lruImageCache);
        imageView.setImageUrl(rockInfo.getImagePath(),imageLoader);
        rockname = (TextView)findViewById(R.id.rock_name);
        rockname.setText(rockInfo.getChinese());

        setRootViewFitSystemWindow(RockInfoActivity.this);
        transparentStatusBar(RockInfoActivity.this);


        NavigationTabStrip navigationTabStrip = (NavigationTabStrip) findViewById(R.id.nts);
        ViewPager viewPager = (ViewPager)findViewById(R.id.vp);
        List<Fragment> fragments = new ArrayList<Fragment>();
        BlankFragment blankFragment = new BlankFragment();
        blankFragment.init(rockInfo);
        PhotoFragment photoFragment = new PhotoFragment();
        photoFragment.init(rockInfo);
        fragments.add(blankFragment);
        fragments.add(photoFragment);
        mFragmentAdapter = new FragmentAdapter(
                this.getSupportFragmentManager(), fragments);
        viewPager.setAdapter(mFragmentAdapter);
        navigationTabStrip.setTabIndex(1, true);
        navigationTabStrip.setViewPager(viewPager);
        navigationTabStrip.setTitles("基本信息", "精品图片展");
        navigationTabStrip.setTitleSize(45);
        navigationTabStrip.setStripColor(Color.parseColor("#0099da"));
        navigationTabStrip.setStripWeight(4);
        navigationTabStrip.setStripFactor(2);
        navigationTabStrip.setStripType(NavigationTabStrip.StripType.LINE);
        navigationTabStrip.setStripGravity(NavigationTabStrip.StripGravity.BOTTOM);
        navigationTabStrip.setTypeface("fonts/typeface.ttf");
        navigationTabStrip.setCornersRadius(2);
        navigationTabStrip.setAnimationDuration(300);
        navigationTabStrip.setInactiveColor(Color.GRAY);
        navigationTabStrip.setActiveColor(Color.parseColor("#0099da"));




    }

    public static ViewGroup getAppRootView(Activity activity) {
        return (ViewGroup) ((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0);
    }

    /**
     *将目标View的paddingTop从0设置为状态栏的高度
     */
    private static void setRootViewFitSystemWindow(Activity activity) {
        ViewGroup rootView = getAppRootView(activity);
        //rootView.setFitsSystemWindows(true);
        rootView.setClipToPadding(true);
    }

    /** * 使状态栏透明 */
    private static void transparentStatusBar(Activity activity) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
        }
        else {
            activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }
    }

}
